# -*- coding: utf-8 -*-
import pymongo
client = pymongo.MongoClient('47.74.21.140')
client.admin.authenticate("admin321", "dsf::6666,,<<", mechanism='SCRAM-SHA-1')
db = client.hotel
import MySQLdb
mysqldb = MySQLdb.connect("127.0.0.1","root","123456789", "shantianjun",charset="utf8")
cursor = mysqldb.cursor()
for y in db.area.find({"tid":1}):
    # import ipdb;ipdb.set_trace()
    cursor.execute("insert into hotelarea (name,level) values ('%s',1)" % y['name'])
    areaid = cursor.lastrowid
    # tmp = cursor.execute(sql)
    for yy in db.area.find({"tid":0,"url":y["url"]}):
        for yyy in yy["name"]:
            cursor.execute('insert into hotelarea (name,level,tid) values ("%s",2,%s)' % (yyy[0],areaid))
            cityid = cursor.lastrowid
            for yyyy in yyy[1]:
                cursor.execute('insert into hotelarea (name,level,tid) values ("%s",3,%s)' % (yyyy.strip(),cityid))

cursor.close()
mysqldb.commit()
